package com.fdb.efp.limit.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.fdb.efp.limit.service.dao.LmtIndivAppExtDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.limit.service.domain.LmtIndivAppExt;
import com.fdb.efp.limit.service.facade.LmtIndivAppExtService;
import com.fdb.efp.limit.service.vo.LmtIndivAppExtVO;

/**
 * <p>
 * 个人授信申请拓展表的Service实现类
 * </p>
 * @author szbd
 * @createDate 2018-09-04 19:51:27
 */
@Service("lmtIndivAppExtService")
public class LmtIndivAppExtServiceImpl implements LmtIndivAppExtService, FrameworkService {
    
    private static Logger logger = LoggerFactory.getLogger(LmtIndivAppExtServiceImpl.class);
    
    @Autowired
    private LmtIndivAppExtDao lmtIndivAppExtDao;
    
    @Override
    public List<LmtIndivAppExtVO> queryAllOwner(LmtIndivAppExtVO inLmtIndivAppExtVo) {
        logger.info("查询本人所属的个人授信申请拓展表记录的请求参数为：" + JSONObject.toJSONString(inLmtIndivAppExtVo));
        if(Objects.isNull(inLmtIndivAppExtVo)){
            return null;
        }
        try {
            List<LmtIndivAppExt> dataList = lmtIndivAppExtDao.queryAllOwnerByPage(inLmtIndivAppExtVo);
            if (Objects.nonNull(dataList)) {
                List<LmtIndivAppExtVO> resultList = new ArrayList<LmtIndivAppExtVO>();
                resultList = (List<LmtIndivAppExtVO>) beansCopy(dataList, LmtIndivAppExtVO.class);
                return resultList;
            } else {
                logger.info("查询本人所属的个人授信申请拓展表记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本人所属的个人授信申请拓展表记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public List<LmtIndivAppExtVO> queryAllCurrOrg(LmtIndivAppExtVO inLmtIndivAppExtVo) {
        logger.info("查询本机构的个人授信申请拓展表记录的请求参数为：" + JSONObject.toJSONString(inLmtIndivAppExtVo));
        if(Objects.isNull(inLmtIndivAppExtVo)){
            return null;
        }
        try {
            List<LmtIndivAppExt> dataList = lmtIndivAppExtDao.queryAllCurrOrgByPage(inLmtIndivAppExtVo);
            if (Objects.nonNull(dataList)) {
                List<LmtIndivAppExtVO> resultList = new ArrayList<LmtIndivAppExtVO>();
                resultList = (List<LmtIndivAppExtVO>) beansCopy(dataList, LmtIndivAppExtVO.class);
                return resultList;
            } else {
                logger.info("查询本机构的个人授信申请拓展表记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本机构的个人授信申请拓展表记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public List<LmtIndivAppExtVO> queryAllCurrDownOrg(LmtIndivAppExtVO inLmtIndivAppExtVo) {
        logger.info("查询本机构及下属机构的个人授信申请拓展表记录的请求参数为：" + JSONObject.toJSONString(inLmtIndivAppExtVo));
        if(Objects.isNull(inLmtIndivAppExtVo)){
            return null;
        }
        try {
            List<LmtIndivAppExt> dataList = lmtIndivAppExtDao.queryAllCurrDownOrgByPage(inLmtIndivAppExtVo);
            if (Objects.nonNull(dataList)) {
                List<LmtIndivAppExtVO> resultList = new ArrayList<LmtIndivAppExtVO>();
                resultList = (List<LmtIndivAppExtVO>) beansCopy(dataList, LmtIndivAppExtVO.class);
                return resultList;
            } else {
                logger.info("查询本机构及下属机构的个人授信申请拓展表记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本机构及下属机构的个人授信申请拓展表记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public int insertLmtIndivAppExt(LmtIndivAppExtVO inLmtIndivAppExtVo) {
        logger.info("新增个人授信申请拓展表数据的参数为：" + JSONObject.toJSONString(inLmtIndivAppExtVo));
        if(Objects.isNull(inLmtIndivAppExtVo)){
            return 0;
        }
        int count = 0;
        try {
            LmtIndivAppExt lmtIndivAppExt = new LmtIndivAppExt();
            beanCopy(inLmtIndivAppExtVo, lmtIndivAppExt);
            count = lmtIndivAppExtDao.insertLmtIndivAppExt(lmtIndivAppExt);
        } catch (Exception e) {
            logger.error("新增个人授信申请拓展表数据发生异常！", e);
            count = -1;
        }
        logger.info("当前新增个人授信申请拓展表数据条数为：" + count);
        return count;
    }
    
    @Override
    public int deleteLmtIndivAppExtByPk(LmtIndivAppExtVO inLmtIndivAppExtVo) {
        logger.info("删除个人授信申请拓展表数据的参数为：" + JSONObject.toJSONString(inLmtIndivAppExtVo));
        if(Objects.isNull(inLmtIndivAppExtVo)){
            return 0;
        }
        int count = 0;
        try {
            LmtIndivAppExt lmtIndivAppExt = new LmtIndivAppExt();
            beanCopy(inLmtIndivAppExtVo, lmtIndivAppExt);
            count = lmtIndivAppExtDao.deleteLmtIndivAppExtByPk(lmtIndivAppExt);
        } catch (Exception e) {
            logger.error("删除个人授信申请拓展表数据发生异常！", e);
            count = -1;
        }
        logger.info("删除的个人授信申请拓展表数据条数为：" + count);
        return count;
    }
    
    @Override
    public int updateLmtIndivAppExtByPk(LmtIndivAppExtVO inLmtIndivAppExtVo) {
        logger.info("修改个人授信申请拓展表数据的参数为：" + JSONObject.toJSONString(inLmtIndivAppExtVo));
        if(Objects.isNull(inLmtIndivAppExtVo)){
            return 0;
        }
        int count = 0;
        try {
            LmtIndivAppExt lmtIndivAppExt = new LmtIndivAppExt();
            beanCopy(inLmtIndivAppExtVo, lmtIndivAppExt);
            count = lmtIndivAppExtDao.updateLmtIndivAppExtByPk(lmtIndivAppExt);
        } catch (Exception e) {
            logger.error("修改数据发生异常！", e);
            count = -1;
        }
        logger.info("修改的个人授信申请拓展表数据条数为" + count);
        return count;
    }
    
    @Override
    public LmtIndivAppExtVO queryLmtIndivAppExtByPk(LmtIndivAppExtVO inLmtIndivAppExtVo) {
        logger.info("根据主键查询个人授信申请拓展表的请求参数为：" + JSONObject.toJSONString(inLmtIndivAppExtVo));
        if(Objects.isNull(inLmtIndivAppExtVo)){
            return null;
        }
        try {
            LmtIndivAppExt lmtIndivAppExt = new LmtIndivAppExt();
            beanCopy(inLmtIndivAppExtVo, lmtIndivAppExt);
            lmtIndivAppExt = lmtIndivAppExtDao.queryLmtIndivAppExtByPk(lmtIndivAppExt);
            if (Objects.nonNull(lmtIndivAppExt)) {
                LmtIndivAppExtVO outLmtIndivAppExtVo = beanCopy(lmtIndivAppExt, new LmtIndivAppExtVO());
                return outLmtIndivAppExtVo;
            } else {
                logger.info("根据主键查询个人授信申请拓展表的记录为空！");
            }
        } catch (Exception e) {
            logger.error("根据主键查询个人授信申请拓展表记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public LmtIndivAppExtVO querySingleLmtIndivAppExtByCondition(LmtIndivAppExtVO inLmtIndivAppExtVo) {
        logger.info("根据条件查询单笔个人授信申请拓展表的请求参数为：" + JSONObject.toJSONString(inLmtIndivAppExtVo));
        if(Objects.isNull(inLmtIndivAppExtVo)){
            return null;
        }
        try {
            LmtIndivAppExt lmtIndivAppExt = new LmtIndivAppExt();
            beanCopy(inLmtIndivAppExtVo, lmtIndivAppExt);
            lmtIndivAppExt = lmtIndivAppExtDao.querySingleLmtIndivAppExtByCondition(lmtIndivAppExt);
            if (Objects.nonNull(lmtIndivAppExt)) {
                LmtIndivAppExtVO outLmtIndivAppExtVo = beanCopy(lmtIndivAppExt, new LmtIndivAppExtVO());
                return outLmtIndivAppExtVo;
            } else {
                logger.info("根据条件查询单笔个人授信申请拓展表的记录为空！");
            }
        } catch (Exception e) {
            logger.error("根据条件查询单笔个人授信申请拓展表记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public List<LmtIndivAppExtVO> queryLmtIndivAppExtByCondition(LmtIndivAppExtVO inLmtIndivAppExtVo) {
        logger.info("条件查询个人授信申请拓展表的请求参数为：" + JSONObject.toJSONString(inLmtIndivAppExtVo));
        if(Objects.isNull(inLmtIndivAppExtVo)){
            return null;
        }
        try {
            List<LmtIndivAppExt> dataList = lmtIndivAppExtDao.queryLmtIndivAppExtByCondition(inLmtIndivAppExtVo);
            if (Objects.nonNull(dataList)) {
                List<LmtIndivAppExtVO> resultList = new ArrayList<LmtIndivAppExtVO>();
                resultList = (List<LmtIndivAppExtVO>) beansCopy(dataList, LmtIndivAppExtVO.class);
                return resultList;
            } else {
                logger.info("条件查询个人授信申请拓展表的数据为空！");
            }
        } catch (Exception e) {
            logger.error("条件查询个人授信申请拓展表发生异常！", e);
        }
        return null;
    }
    
    @Override
    public List<LmtIndivAppExtVO> queryLmtIndivAppExtByConditionByPage(LmtIndivAppExtVO inLmtIndivAppExtVo) {
        logger.info("条件分页查询个人授信申请拓展表的请求参数为：" + JSONObject.toJSONString(inLmtIndivAppExtVo));
        if(Objects.isNull(inLmtIndivAppExtVo)){
            return null;
        }
        try {
            List<LmtIndivAppExt> dataList = lmtIndivAppExtDao.queryLmtIndivAppExtByConditionByPage(inLmtIndivAppExtVo);
            if (Objects.nonNull(dataList)) {
                List<LmtIndivAppExtVO> resultList = new ArrayList<LmtIndivAppExtVO>();
                resultList = (List<LmtIndivAppExtVO>) beansCopy(dataList, LmtIndivAppExtVO.class);
                return resultList;
            } else {
                logger.info("条件分页查询个人授信申请拓展表的数据为空！");
            }
        } catch (Exception e) {
            logger.error("条件分页查询个人授信申请拓展表发生异常！", e);
        }
        return null;
    }
}